﻿#include "SignalConfigDialog.h"

SignalConfigDialog::SignalConfigDialog( wxWindow* parent )
:
ViewConfig( parent )
{
	//tTime->SetMin(3);
	//tTime->SetMax(60);
}
void SignalConfigDialog::Configure(SignalClass *pSig)
{
	switch((int)pSig->Gain)
	{
	case 1:
		m_Gain->SetSelection(0);
		break;
	case 5:
		m_Gain->SetSelection(1);
		break;
	case 10:
		m_Gain->SetSelection(2);
		break;
	case 50: 
		m_Gain->SetSelection(3);
		break;
	case 100:
		m_Gain->SetSelection(4);
		break;
	}

	if(pSig->GetDetrend())
	{
		m_Detrend->SetSelection(0);	
	}else
	{
		m_Detrend->SetSelection(1);	
	}

	if (pSig->Color.getAlpha() == 0)
	{
		m_Visible->SetSelection(1);
	}
	else
	{
		m_Visible->SetSelection(0);
	}
	
	//tTime->SetValue(pSig->lRecord/pSig->frequency);

	int Temp;
	memcpy(&Temp,&pSig->Color,4);
	
	int	Red	= 0xFF & (Temp>>16);
	int Green	= 0xFF & (Temp>>8);
	int Blue	= 0xFF & Temp;
	
	m_Colour->SetColour(wxColour(Red,Green,Blue));
	m_pSig = pSig;
	if(1 == ShowModal())
	{
		switch(m_Gain->GetSelection())
		{
		case 0:
			pSig->Gain = 1;
			break;
		case 1:
			pSig->Gain = 5;
			break;
		case 2:
			pSig->Gain = 10;
			break;
		case 3:
			pSig->Gain = 50;
			break;
		case 4:
			pSig->Gain = 100;
			break;
		}
		pSig->MinDyn = pSig->MinDyn/pSig->Gain;
		pSig->MaxDyn = pSig->MaxDyn/pSig->Gain;
		pSig->SetDetrend(m_Detrend->GetSelection() == 0);
		if (this->m_Visible->GetSelection()==1) 
		{
			m_pSig->Color.setAlpha(0);
		}
		else
		{
			wxColour Col = 	m_Colour->GetColour();
			m_pSig->Color = video::SColor(255,Col.Red(),Col.Green(),Col.Blue());
		}
		//pSig->secLength = this->tTime->GetValue(); 
	}

}

void SignalConfigDialog::OnApply( wxCommandEvent& event )
{
	switch(m_Gain->GetSelection())
	{
	case 0:
		m_pSig->Gain = 1;
		break;
	case 1:
		m_pSig->Gain = 5;
		break;
	case 2:
		m_pSig->Gain = 10;
		break;
	case 3:
		m_pSig->Gain = 50;
		break;
	case 4:
		m_pSig->Gain = 100;
		break;
	}
	m_pSig->SetDetrend(m_Detrend->GetSelection() == 0);
	if (this->m_Visible->GetSelection()==1) 
	{
		m_pSig->Color.setAlpha(0);
	}
	else
	{
		wxColour Col = 	m_Colour->GetColour();
		m_pSig->Color = video::SColor(255,Col.Red(),Col.Green(),Col.Blue());
	}
}